package ru.passivemoney.manage.orders;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ru.passivemoney.common.UtilsOrders;
import ru.passivemoney.root.EngineHolder;

import com.dukascopy.api.IOrder;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;

public class OrdersSupervisor {
	
	private static final Logger logger = LoggerFactory.getLogger(OrdersSupervisor.class);
	
	public static final boolean checkOrders() throws JFException{
		boolean ok = true;
		int count = 0;
		int engineCount = 0;
		
		for(Instrument instrument : Instrument.values()){
			count += OrdersHolder.getOpenedOrders(instrument).size();
		}
		
		for(IOrder order : EngineHolder.getEngine().getOrders()){
			if(UtilsOrders.isOrderOpenedOrFilled(order))
				engineCount++;
		}
		
		if(count != engineCount){
			logger.error("ATTENTION! OpenedOrders count {} differs from engine opened orders {}", count, engineCount);
		}
		
		return ok;
	}

}
